<template>
  <el-cascader
    :value="value"
    :options="options"
    :props="paramsProps"
    separator="-"
    @change="handleChange"
  />
</template>

<script>
import { getdept } from '@/api/department'
import { gettree } from '@/utils/gettree'

export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      options: [],
      paramsProps: {
        label: 'name',
        value: 'id'
      }
    }
  },
  created() {
    this.initdept()
  },
  methods: {
    handleChange(value) {
      console.log(value)
      if (value.length > 0) {
        this.$emit('input', value[value.length - 1])
      }
    },
    async initdept() {
      this.options = gettree(await getdept(), 0)
    }

  }
}
</script>

<style>
</style>
